package org.example.hotel.schedule;

import org.example.hotel.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduleTaskRunner {

    @Autowired
    private ScheduleService scheduleService;

    /*@Scheduled(fixedRate = 1000)
    public void runReschedule() {
        scheduleService.rescheduleRooms();
    }

    @Scheduled(fixedRate = 1000)
    public void runSimulateTemperatureChange() {
        scheduleService.simulateTemperatureChange();
    }*/

    @Scheduled(fixedRate = 1000)
    public synchronized void runScheduleLoop() {
        scheduleService.simulateTemperatureChange(); // 先处理温度变化
        scheduleService.rescheduleRooms();           // 再做调度
    }

}

